/**
 * 后台JS
 * Created by crstu on 2016/4/25.
 */

//初始化左侧菜单
$(function () {
    $.getJSON('/public/get-menu-data.html', function (response) {
        if(response.data){
            $container = $('.navbar-nav');
            $.each(response.data, function (i, n) {
                var html = '<li><a href="javascript:;" data-toggle="collapse" data-target="#child'+i+'">'
                        +'<i class="fa fa-fw fa-'+n.icon+'"></i> <b>'+n.title+'</b><i class="fa fa-fw fa-caret-down"></i></a>';
                if(n.child){
                    html += '<ul id="child'+i+'" class="collapse">';
                    $.each(n.child, function (k, v) {
                        if(v[3]){
                            url = '/' + v[0] + '/' + v[1] + '.html';
                            html += '<li><a href="'+url+'">'+v[2]+'</a></li>';
                        }
                    });
                    html += '</ul>';
                }
                html += '</li>';
                $container.append(html);
            })
        }
    })
});

//后台提示插件
function jNotify(message, type, duration) {
    if(!arguments[2]) duration = 3000;//显示默认值
    $container = $('#jNotify');
    $container.html("");//去除之前已经显示过的
    var html = $('<div class="notify notify-' + type + '">' + message + '</div>').fadeIn(500);
    $container.append(html);
    setTimeout(function() {
        html.remove();
    }, duration);
};